/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.member.service.plugins;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.member.entity.Member;
import com.apache.member.manager.MemberManager;
import com.apache.tools.ClassToolsUtil;

/**
 * description:  会员新增插件
 * @author dwusoft 创建时间：2016-7-28  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class MemberDelPlugin implements PluginConnector {

	private Logger log = Logger.getLogger(MemberDelPlugin.class);

	private MemberManager memberManager;

	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		try {
			delMember(result, vo);
		} catch (Exception e) {
			result.setResult("false");
			result.setMessage("执行失败！");
		}
		return result;
	}

	/**
	 * description: 删除会员信息。
	 * 
	 */
	private void delMember(ResultEntity result, ParamsVo vo) {
		Member member = new Member();
		member = (Member) ClassToolsUtil.getInstance().convert2Bean(vo.getParams(), member);
		if (member != null) {
			ParamsVo<Member> memberVo = new ParamsVo<Member>();
			if (Validator.isNotNull(member.getMemberId())) {
				memberVo.setInfoId(member.getMemberId());
				boolean flag = memberManager.deleteInfo(memberVo);
				if (!flag) {
					result.setMessage("删除失败");
				} else {
					result.setMessage("删除成功");
					result.setEntity(member.getMemberId());
				}
			} else {
				result.setMessage("修改用户不存在：用户唯一标识未传递或传递的唯一标识不存在");

			}
		}
	}

	public void setMemberManager(MemberManager memberManager) {
		this.memberManager = memberManager;
	}

}
